﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions; 

namespace CSP.Core
{
    public class FormValidator
    {

        /// <summary>
        /// Checks if a string is a valid integer
        /// </summary>
        public static bool IsNumber(string num)
        {
            try
            {
                Int32.Parse(num);
            }
            catch
            {
                return false;
            }
            return true;

        }

        /// <summary>
        /// Checks if a string is a valid decimal
        /// </summary>
        public static bool IsDecimal(string num)
        {
            try
            {
                Decimal.Parse(num);
            }
            catch
            {
                return false;
            }
            return true;

        }

        /// <summary>
        /// Checks if a string is a valid email address
        /// </summary>
        public static bool IsEmail(string email)
        {
            string pattern = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.
    (com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[a-zA-Z]{2})$";
          
            Regex check = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);
            bool valid = false;

            if (string.IsNullOrEmpty(email))
            {
                valid = false;
            }
            else
            {
                valid = check.IsMatch(email);
            }
            return valid;


        }



    }
}
